all : parsec-build
HOOKS_DIR=../tools/hooks/

parsec-core : parsec-2.1/.parsec_source
parsec-2.1/.parsec_source :
	wget -c http://parsec.cs.princeton.edu/download/2.1/parsec-2.1-core.tar.gz
	tar -x -f parsec-2.1-core.tar.gz --keep-old-files ; true
	wget -c http://parsec.cs.princeton.edu/download/2.1/bugfixes/parsec-ocreat.patch
	wget -c http://parsec.cs.princeton.edu/download/2.1/bugfixes/ferret-deadlock.patch
	wget -c http://parsec.cs.princeton.edu/download/2.1/bugfixes/blackscholes.c.patch
	wget -c http://parsec.cs.princeton.edu/download/2.1/bugfixes/blackscholes.tbb.cpp.patch
	wget -c http://parsec.cs.princeton.edu/download/2.1/bugfixes/streamcluster_barrier.patch
	patch -p1 -dparsec-2.1 < parsec-ocreat.patch
	patch -p1 -dparsec-2.1 < ferret-deadlock.patch
	patch -p0 -dparsec-2.1/pkgs/apps/blackscholes/src < blackscholes.c.patch
	patch -p0 -dparsec-2.1/pkgs/apps/blackscholes/src < blackscholes.tbb.cpp.patch
	patch -p1 -dparsec-2.1 < streamcluster_barrier.patch

	patch -p0 -dparsec-2.1 < patches/parsec-ssl-nodoc.patch
	patch -p1 -dparsec-2.1 < patches/ssl-asm.patch
	patch -p1 -dparsec-2.1 < patches/raytrace-unistd-gcc-fix.patch
	patch -p3 -dparsec-2.1 < patches/raytrace-Xext-fix.patch
	# Once the download succeeded and we applied all patches, mark as done
	touch parsec-2.1/.parsec_source

parsec-input-sim : parsec-2.1/pkgs/apps/blackscholes/inputs/input_simsmall.tar
parsec-2.1/pkgs/apps/blackscholes/inputs/input_simsmall.tar :
	wget -c http://parsec.cs.princeton.edu/download/2.1/parsec-2.1-sim.tar.gz
	tar xf parsec-2.1-sim.tar.gz

parsec-input-native : parsec-2.1/pkgs/apps/blackscholes/inputs/input_native.tar
parsec-2.1/pkgs/apps/blackscholes/inputs/input_native.tar :
	wget -c http://parsec.cs.princeton.edu/download/2.1/parsec-2.1-native.tar.gz
	tar xf parsec-2.1-native.tar.gz

parsec-dependencies :
	./checkdependencies.py

parsec-build : parsec-dependencies parsec-core parsec-input-sim
	make -C ${HOOKS_DIR}
	cd parsec-2.1; ./bin/parsecmgmt -a build -p bench -c gcc-sniper
	cd parsec-2.1; ./bin/parsecmgmt -a clean -c gcc-sniper

clean :
	make -C ${HOOKS_DIR} clean
	cd parsec-2.1; ./bin/parsecmgmt -a uninstall -p all -c gcc-sniper
